﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Revis.VClinicNet.Core.Domain;

using AutoMapper;

namespace Revis.VClinicNet.App.Internal.Dto.Mappers
{
    public class PatientDtoMapper : IDtoMapper
    {
        public static Func<Patient, string> Name = (p) => {
            return p.Personal.FirstName + " " + p.Personal.Surname;
        };

        public static Func<Patient, string> Address = (p) => {
            return p.Personal.Address.StreetName + " " + p.Personal.Address.HomeNumber;
        };

        public static Func<Patient, string> Pesel = (p) => {
            return p.Personal.Pesel;
        };

        public static Func<Patient, IList<Entry>> Entries = (p) => {
            return p.Card.Entries;
        };

        public void Map()
        {
            Mapper.CreateMap<Address, AddressDto>();
            Mapper.CreateMap<PersonalData, PersonalDataDto>();

            Mapper.CreateMap<Patient, PatientDto>();
            Mapper.CreateMap<Patient, PatientCardDto>()
                .ForMember(e => e.Name, mo=> mo.MapFrom(p => Name(p)))
                .ForMember(e => e.Entries, mo => mo.MapFrom(p => Entries(p)));

            Mapper.CreateMap<Patient, PatientEditDto>();

            Mapper.CreateMap<Patient, PatientInfoDto>()
                .ForMember(p => p.Address, mo => mo.MapFrom(p => Address(p)))
                .ForMember(p => p.Name, mo => mo.MapFrom(p => Name(p)))
                .ForMember(p => p.Pesel, mo => mo.MapFrom(p => Pesel(p)));
        }
    }
}
